
 <!DOCTYPE HTML>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  
    <title>React使用笔记6--使用flux&quot;单向流动&quot;你的应用 | Here. There.</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=3, minimum-scale=1">
    
    <meta name="author" content="被删">
    
    <meta name="description" content="最近在学习使用React作为前端的框架，《React使用笔记》系列用于记录过程中的一些使用和解决方法。本文简单介绍React Flux架构，以及记录使用flux改造当前应用的过程。">
    
    
    
    
    <link rel="alternate" href="/atom.xml" title="Here. There." type="application/atom+xml">
    
    
    <link rel="icon" href="/img/favicon.ico">
    
    
    <link rel="apple-touch-icon" href="/img/pacman.jpg">
    <link rel="apple-touch-icon-precomposed" href="/img/pacman.jpg">
    
    <link rel="stylesheet" href="/css/style.css">
    
<script type="text/javascript">
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "//hm.baidu.com/hm.js?3d902de4a19cf2bf179534ffd2dd7b7f";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>

</head>

  <body>
    <header>
      <div>
		
			<div id="imglogo">
				<a href="/"><img src="/img/sun.png" alt="Here. There." title="Here. There."/></a>
			</div>
			
			<div id="textlogo">
				<h1 class="site-name"><a href="/" title="Here. There.">Here. There.</a></h1>
				<h2 class="blog-motto">Love ice cream. Love sunshine. Love life. Love the world. Love myself. Love you.</h2>
			</div>
			<div class="navbar"><a class="navbutton navmobile" href="#" title="菜单">
			</a></div>
			<nav class="animated">
				<ul>
					
						<li><a href="/">首页</a></li>
					
						<li><a href="https://github.com/godbasin/godbasin.github.io">所有文章</a></li>
					
						<li><a href="/archives">归档</a></li>
					
						<li><a href="/categories">分类</a></li>
					
						<li><a href="https://godbasin.github.io/front-end-playground">前端游乐场</a></li>
					
						<li><a href="/about">关于我</a></li>
					
				</ul>
			</nav>			
</div>

    </header>
    <div id="container">
      <div id="main" class="post" itemscope itemprop="blogPost">
	<article itemprop="articleBody"> 
		<header class="article-info clearfix">
  <h1 itemprop="name">
    
      <a href="/2016/08/21/react-notes-6-use-flux/" title="React使用笔记6--使用flux&quot;单向流动&quot;你的应用" itemprop="url">React使用笔记6--使用flux&quot;单向流动&quot;你的应用</a>
  </h1>
  <p class="article-author">By
    
      <a href="https://godbasin.github.io" title="被删">被删</a>
    </p>
  <p class="article-time">
    <time datetime="2016-08-20T18:19:51.000Z" itemprop="datePublished">2016-08-21</time>
    更新日期:<time datetime="2018-12-18T15:37:47.626Z" itemprop="dateModified">2018-12-18</time>
    
  </p>
</header>
	<div class="article-content">
		
		
		<div id="toc" class="toc-article">
			<strong class="toc-title">文章目录</strong>
		<ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#React-Flux架构简介"><span class="toc-number">1.</span> <span class="toc-text">React Flux架构简介</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#什么是Flux"><span class="toc-number">1.1.</span> <span class="toc-text">什么是Flux</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Flux基本概念"><span class="toc-number">1.2.</span> <span class="toc-text">Flux基本概念</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Flux数据流"><span class="toc-number">1.3.</span> <span class="toc-text">Flux数据流</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#参考"><span class="toc-number">1.4.</span> <span class="toc-text">参考</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#使用Flux"><span class="toc-number">2.</span> <span class="toc-text">使用Flux</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#目录组织"><span class="toc-number">2.1.</span> <span class="toc-text">目录组织</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#添加HeaderStore"><span class="toc-number">2.2.</span> <span class="toc-text">添加HeaderStore</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#通过Controller-View传递数据"><span class="toc-number">2.3.</span> <span class="toc-text">通过Controller-View传递数据</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#添加Actions"><span class="toc-number">2.4.</span> <span class="toc-text">添加Actions</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#注册Store到Dispatcher"><span class="toc-number">2.5.</span> <span class="toc-text">注册Store到Dispatcher</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#结束语"><span class="toc-number">3.</span> <span class="toc-text">结束语</span></a></li></ol>
		</div>
		
		<p>最近在学习使用React作为前端的框架，《React使用笔记》系列用于记录过程中的一些使用和解决方法。<br>本文简单介绍React Flux架构，以及记录使用flux改造当前应用的过程。<br><a id="more"></a></p>
<h2 id="React-Flux架构简介"><a href="#React-Flux架构简介" class="headerlink" title="React Flux架构简介"></a>React Flux架构简介</h2><hr>
<h3 id="什么是Flux"><a href="#什么是Flux" class="headerlink" title="什么是Flux"></a>什么是Flux</h3><p>Flux是Facebook用来构建客户端Web应用的应用架构。它利用单向数据流的方式来组合React中的视图组件。<br>Flux是一种架构思想，专门解决软件的结构问题。它跟MVC架构是同一类东西，更像一个模式而不是一个正式的框架。</p>
<h3 id="Flux基本概念"><a href="#Flux基本概念" class="headerlink" title="Flux基本概念"></a>Flux基本概念</h3><ul>
<li><p>Views： 视图层</p>
<ul>
<li>controller-view<ul>
<li>可以理解成MVC模型中的controller，它一般由应用的顶层容器充当，负责从store中获取数据并将数据传递到子组件中。</li>
<li>简单的应用一般只有一个controller-view，复杂应用中也可以有多个。</li>
<li>controller-view是应用中唯一可以操作state的地方(setState())</li>
</ul>
</li>
<li>view(UI组件)<ul>
<li>ui-component职责单一只允许调用action触发事件，数据从由上层容器通过属性传递过来。</li>
</ul>
</li>
</ul>
</li>
<li><p>Action（动作）：视图层发出的消息，可通过调用它来响应用户交互</p>
<ul>
<li>是dispatcher提供了一个可以允许我们向store中触发分发的方法</li>
<li>包含了一个数据的payload。action生成被包含进一个语义化的辅助方法中，来发送action到dispatcher</li>
</ul>
</li>
<li><p>Dispatcher（派发器）：用来接收Actions、执行回调函数</p>
<ul>
<li>dispatcher就像是一个中央的集线器，管理着所有的数据流</li>
<li>本质上是store callback的注册表，本身并没有实际的高度功能</li>
<li>每个Store注册它自己并提供一个回调函数</li>
</ul>
</li>
<li><p>Store（数据层）：负责封装应用的业务逻辑跟数据的交互</p>
<ul>
<li>用来存放应用的状态，一旦发生变动，就提醒Views要更新页面</li>
<li>Store中包含应用所有的数据，是应用中唯一的数据发生变更的地方</li>
<li>Store中没有赋值接口—所有数据变更都是由dispatcher发送到store，新的数据随着Store触发的change事件传回view</li>
</ul>
</li>
</ul>
<h3 id="Flux数据流"><a href="#Flux数据流" class="headerlink" title="Flux数据流"></a>Flux数据流</h3><p><img src="https://github-imglib-1255459943.cos.ap-chengdu.myqcloud.com/bg2016011503.png" alt="image"></p>
<ul>
<li>store在dispatcher中注册，并提供相应的回调。回调会接收action并把它当成自己的一个参数。</li>
<li>通过调用action来响应用户交互。</li>
<li>当action被触发，回调函数会使用switch语句来解析action中的type参数，并在合适的type下提供钩子来执行内部方法。</li>
<li>action通过dispatcher来响应store中的state更新。</li>
<li>store更新完成之后，会向应用中广播一个change事件，views可以选择响应事件来重新获取新的数据并更新。</li>
</ul>
<h3 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h3><p><a href="http://www.ruanyifeng.com/blog/2016/01/flux.html" target="_blank" rel="external">《Flux 架构入门教程》</a><br><a href="http://www.cocoachina.com/webapp/20150928/13600.html" target="_blank" rel="external">《谈一谈我对 React Flux 架构的理解》</a></p>
<h2 id="使用Flux"><a href="#使用Flux" class="headerlink" title="使用Flux"></a>使用Flux</h2><hr>
<p>这里使用改造头部组件作为例子，简述使用flux过程。</p>
<h3 id="目录组织"><a href="#目录组织" class="headerlink" title="目录组织"></a>目录组织</h3><p>使用flux之后，目录组织如下：<br><img src="https://github-imglib-1255459943.cos.ap-chengdu.myqcloud.com/FCB5.tmp.png" alt="image"><br>这里再简单描述一下新增和改变的文件：</p>
<ul>
<li>actions: 存放Flux的Action文件</li>
<li>components: 存放Flux的Views文件（包括Controller-Views）</li>
<li>dispatcher: 存放Flux的Dispatcher文件</li>
<li>stores: 存放Flux的Store文件</li>
</ul>
<h3 id="添加HeaderStore"><a href="#添加HeaderStore" class="headerlink" title="添加HeaderStore"></a>添加HeaderStore</h3><p>在stores文件夹添加HeaderStore.js文件，封装头部相关的业务逻辑和数据交互。<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> EventEmitter = <span class="built_in">require</span>(<span class="string">'events'</span>).EventEmitter;</div><div class="line"><span class="keyword">var</span> assign = <span class="built_in">require</span>(<span class="string">'object-assign'</span>);</div><div class="line"><span class="comment">//封装头部相关的业务逻辑和数据交互</span></div><div class="line"><span class="keyword">var</span> HeaderStore = assign(&#123;&#125;, EventEmitter.prototype, &#123;</div><div class="line">  <span class="attr">menus</span>: [&#123;</div><div class="line">    <span class="attr">title</span>: <span class="string">'index'</span>, <span class="comment">//title用于储存路由对应的路径</span></div><div class="line">    href: <span class="string">'?#/index'</span>, <span class="comment">//href用于设定该菜单跳转路由</span></div><div class="line">    text: <span class="string">'首页'</span>, <span class="comment">//text用于储存该菜单显示名称</span></div><div class="line">  &#125;, &#123;</div><div class="line">    <span class="attr">title</span>: <span class="string">'others'</span>,</div><div class="line">    <span class="attr">href</span>: <span class="string">'?#/other'</span>,</div><div class="line">    <span class="attr">text</span>: <span class="string">'其他'</span>,</div><div class="line">  &#125;],</div><div class="line">  <span class="attr">usermenus</span>: [&#123;</div><div class="line">    <span class="attr">click</span>: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;&#125;, <span class="comment">//click用于设置该菜单点击事件</span></div><div class="line">    text: <span class="string">'退出'</span>, <span class="comment">//text用于储存该菜单显示名称</span></div><div class="line">  &#125;],</div><div class="line">  <span class="attr">clock</span>: <span class="string">''</span>, <span class="comment">//clock用于保存时钟</span></div><div class="line">  getMenus: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;<span class="keyword">return</span> <span class="keyword">this</span>.menus;&#125;, <span class="comment">//获取menus</span></div><div class="line">  getUsermenus: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;<span class="keyword">return</span> <span class="keyword">this</span>.usermenus;&#125;, <span class="comment">//获取usermenus</span></div><div class="line">  getClock: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;<span class="keyword">return</span> <span class="keyword">this</span>.clock;&#125;, <span class="comment">//获取clock</span></div><div class="line">  clockRender: <span class="function"><span class="keyword">function</span>(<span class="params">callback</span>) </span>&#123; <span class="comment">//刷新时钟</span></div><div class="line">    <span class="keyword">let</span> numberStandard = <span class="function"><span class="keyword">function</span>(<span class="params">num</span>) </span>&#123;</div><div class="line">        <span class="keyword">let</span> _val = <span class="built_in">Number</span>(num),</div><div class="line">          _num;</div><div class="line">        _num = (_val &lt; <span class="number">10</span>) ? (<span class="string">'0'</span> + _val) : (<span class="string">''</span> + _val);</div><div class="line">        <span class="keyword">return</span> _num;</div><div class="line">      &#125;,</div><div class="line">      _date = <span class="keyword">new</span> <span class="built_in">Date</span>();</div><div class="line">    <span class="keyword">this</span>.clock = _date.getFullYear() + <span class="string">'年'</span> + (_date.getMonth() + <span class="number">1</span>) + <span class="string">'月'</span> +</div><div class="line">      _date.getDate() + <span class="string">'日'</span> + <span class="string">' '</span> + numberStandard(_date.getHours()) + <span class="string">':'</span> + numberStandard(_date.getMinutes()) +</div><div class="line">      <span class="string">':'</span> + numberStandard(_date.getSeconds());</div><div class="line">    callback(); <span class="comment">//可使用回调触发刷新</span></div><div class="line">  &#125;,</div><div class="line">&#125;);</div><div class="line"><span class="built_in">module</span>.exports = HeaderStore;</div></pre></td></tr></table></figure></p>
<h3 id="通过Controller-View传递数据"><a href="#通过Controller-View传递数据" class="headerlink" title="通过Controller-View传递数据"></a>通过Controller-View传递数据</h3><p>在components文件夹添加HeaderController.jsx和Header.jsx文件。</p>
<ul>
<li>HeaderController.jsx<br>HeaderController负责从Headerstore中获取数据并将数据传递到Header中，以及定义相关交互逻辑。</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">import</span> React <span class="keyword">from</span> <span class="string">'react'</span>; <span class="comment">//导入react组件</span></div><div class="line"><span class="keyword">import</span> HeaderStore <span class="keyword">from</span> <span class="string">'../stores/HeaderStore.js'</span>;  <span class="comment">//获取HeaderStore</span></div><div class="line"><span class="keyword">import</span> HeaderActions <span class="keyword">from</span> <span class="string">'../actions/HeaderActions.js'</span>; <span class="comment">//获取HeaderActions</span></div><div class="line"><span class="keyword">import</span> Header <span class="keyword">from</span> <span class="string">'./Header.jsx'</span>; <span class="comment">//获取子组件Header</span></div><div class="line"></div><div class="line"><span class="keyword">const</span> HeaderController = React.createClass(&#123;</div><div class="line">  <span class="attr">getDefaultProps</span> : <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123; <span class="comment">//设置props数据</span></div><div class="line">    <span class="keyword">return</span> &#123;</div><div class="line">      <span class="attr">menus</span>: HeaderStore.getMenus(), <span class="comment">//从HeaderStore获取menus数据</span></div><div class="line">      usermenus:  HeaderStore.getUsermenus(), <span class="comment">//从HeaderStore获取usermenus数据</span></div><div class="line">    &#125;;</div><div class="line">  &#125;,</div><div class="line">  <span class="attr">getInitialState</span>: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123; <span class="comment">//设置state数据</span></div><div class="line">    <span class="keyword">return</span> &#123;<span class="attr">clock</span>: HeaderStore.getClock()&#125;; <span class="comment">//从HeaderStore获取clock数据</span></div><div class="line">  &#125;,</div><div class="line">  <span class="attr">setClock</span>: <span class="function"><span class="keyword">function</span>(<span class="params">time</span>) </span>&#123; <span class="comment">//从HeaderStore获取clock并更新状态</span></div><div class="line">    <span class="keyword">this</span>.setState(&#123;<span class="attr">clock</span>: HeaderStore.getClock()&#125;);</div><div class="line">  &#125;,</div><div class="line">  <span class="attr">componentDidMount</span>: <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</div><div class="line">    <span class="keyword">var</span> that = <span class="keyword">this</span>;</div><div class="line">    <span class="keyword">this</span>.interval = setInterval(<span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123; <span class="comment">//设置定时器500ms刷新一次clock</span></div><div class="line">      HeaderActions.clockRender(that.setClock); <span class="comment">//传入回调触发刷新</span></div><div class="line">    &#125;, <span class="number">500</span>);</div><div class="line">  &#125;,</div><div class="line">  <span class="attr">componentWillUnmount</span>: <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</div><div class="line">    clearInterval(<span class="keyword">this</span>.interval); <span class="comment">//移除定时器</span></div><div class="line">  &#125;,</div><div class="line">  render() &#123;</div><div class="line">    <span class="comment">//将数据以props传入子组件</span></div><div class="line">    <span class="keyword">return</span> <span class="xml"><span class="tag">&lt;<span class="name">Header</span> <span class="attr">clock</span>=<span class="string">&#123;this.state.clock&#125;</span> <span class="attr">menus</span>=<span class="string">&#123;this.props.menus&#125;</span> <span class="attr">usermenus</span>=<span class="string">&#123;this.props.usermenus&#125;</span> <span class="attr">active</span>=<span class="string">&#123;this.props.active&#125;</span>  /&gt;</span>;</span></div><div class="line">  &#125;</div><div class="line">&#125;);</div><div class="line"></div><div class="line">module.exports = HeaderController;</div></pre></td></tr></table></figure>
<p>当然，如果需要更新页面的事件变多了，也可以使用event事件来进行广播哦。</p>
<ul>
<li>Header.jsx<br>Header只负责简单的页面显示即可。</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">import</span> React <span class="keyword">from</span> <span class="string">'react'</span>; <span class="comment">//导入react组件</span></div><div class="line"><span class="keyword">import</span> &#123; NavDropdown, MenuItem, Navbar, Nav &#125; <span class="keyword">from</span> <span class="string">'react-bootstrap'</span>;</div><div class="line"></div><div class="line"><span class="keyword">const</span> Header = React.createClass(&#123;</div><div class="line">  render() &#123;</div><div class="line">    <span class="keyword">let</span> active = <span class="keyword">this</span>.props.active;</div><div class="line">    <span class="keyword">return</span> (</div><div class="line">      &lt;Navbar className="header" fluid&gt;</div><div class="line">        &lt;Navbar.Header className="navbar-header"&gt;</div><div class="line">          &lt;Navbar.Brand&gt;Godbasin&lt;/Navbar.Brand&gt;</div><div class="line">        &lt;/Navbar.Header&gt;</div><div class="line">        &lt;Navbar.Collapse id="bs-example-navbar-collapse-1"&gt;</div><div class="line">          &lt;Nav navbar&gt;     	</div><div class="line">          &#123;							</div><div class="line">            this.props.menus.map(function(menu, i) &#123;</div><div class="line">              return (&lt;li key=&#123;i&#125; className=&#123; menu.title == active ? "active" : ""&#125;&gt;&lt;a href=&#123;menu.href&#125;&gt;&#123; menu.text &#125;&lt;span className="sr-only"&gt;(current)&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;);</div><div class="line">            &#125;)</div><div class="line">          &#125;</div><div class="line">          &lt;/Nav&gt;</div><div class="line">          &lt;Nav navbar pullRight&gt;</div><div class="line">            &lt;li&gt;&lt;a&gt;&#123; this.props.clock &#125;&lt;/a&gt;&lt;/li&gt;</div><div class="line">            &lt;NavDropdown title="菜单" id="top-aside-menu"&gt;</div><div class="line">              &#123;</div><div class="line">                this.props.usermenus.map(function(usermenu,i) &#123;</div><div class="line">                  return (&lt;MenuItem key=&#123;i&#125;&gt;&#123; usermenu.text &#125;&lt;/MenuItem&gt;);</div><div class="line">                &#125;)</div><div class="line">              &#125;</div><div class="line">            &lt;/NavDropdown&gt;</div><div class="line">          &lt;/Nav&gt;</div><div class="line">        &lt;/Navbar.Collapse&gt;</div><div class="line">      &lt;/Navbar&gt;</div><div class="line">    )</div><div class="line">  &#125;</div><div class="line">&#125;);</div><div class="line"></div><div class="line">module.exports = Header;</div></pre></td></tr></table></figure>
<h3 id="添加Actions"><a href="#添加Actions" class="headerlink" title="添加Actions"></a>添加Actions</h3><p>在actions文件夹添加HeaderActions.js文件，负责发送Action到Dispatcher。<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">import</span> AppDispatcher <span class="keyword">from</span> <span class="string">'../dispatcher/AppDispatcher.js'</span>;</div><div class="line"></div><div class="line"><span class="keyword">var</span> HeaderActions = &#123;</div><div class="line">  <span class="attr">clockRender</span>: <span class="function"><span class="keyword">function</span> (<span class="params">callback</span>) </span>&#123; <span class="comment">//定义clockRender事件</span></div><div class="line">    AppDispatcher.dispatch(&#123;</div><div class="line">      <span class="attr">actionType</span>: <span class="string">'CLOCK_RENDER'</span>, <span class="comment">//发送Action的类型</span></div><div class="line">      callback: callback <span class="comment">//携带回调事件参数</span></div><div class="line">    &#125;);</div><div class="line">  &#125;,</div><div class="line">&#125;;</div><div class="line"></div><div class="line"><span class="built_in">module</span>.exports = HeaderActions;</div></pre></td></tr></table></figure></p>
<h3 id="注册Store到Dispatcher"><a href="#注册Store到Dispatcher" class="headerlink" title="注册Store到Dispatcher"></a>注册Store到Dispatcher</h3><p>在dispacther文件夹添加AppDispatcher.js文件，用来注册所有的Store。<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">import</span> &#123; Dispatcher &#125; <span class="keyword">from</span> <span class="string">'flux'</span>; <span class="comment">//导入react组件</span></div><div class="line"><span class="keyword">import</span> HeaderStore <span class="keyword">from</span> <span class="string">'../stores/HeaderStore.js'</span>; <span class="comment">//导入HeaderStore</span></div><div class="line"></div><div class="line"><span class="keyword">var</span> AppDispatcher = <span class="keyword">new</span> Dispatcher();</div><div class="line">AppDispatcher.register(<span class="function"><span class="keyword">function</span>(<span class="params">action</span>) </span>&#123;</div><div class="line">  <span class="keyword">switch</span> (action.actionType) &#123;</div><div class="line">    <span class="keyword">case</span> <span class="string">'CLOCK_RENDER'</span>:</div><div class="line">      HeaderStore.clockRender(action.callback); <span class="comment">//执行clockRender事件</span></div><div class="line">      <span class="keyword">break</span>;</div><div class="line">    <span class="keyword">default</span>:</div><div class="line">  &#125;</div><div class="line">&#125;);</div><div class="line"></div><div class="line"><span class="built_in">module</span>.exports = AppDispatcher;</div></pre></td></tr></table></figure></p>
<h2 id="结束语"><a href="#结束语" class="headerlink" title="结束语"></a>结束语</h2><hr>
<p>虽然说使用Flux会使得代码量增加了不少，但这样的架构模式也不失为一种管理应用逻辑的方法呢，使用之后应用结构也清晰很多了。<br><a href="https://github.com/godbasin/godbasin.github.io/tree/blog-codes/react-notes/6-use-flux" target="_blank" rel="external">此处查看项目代码（仅包含app部分）</a><br><a href="http://react-notes.godbasin.com/6-use-flux/index.html" target="_blank" rel="external">此处查看页面效果</a></p>
  
		
		<p style="margin-top:50px;">
			查看Github有更多内容噢：<a href="https://github.com/godbasin">https://github.com/godbasin</a>
			<br>
			更欢迎来<a href="https://godbasin.github.io/front-end-playground">被删的前端游乐场</a>边撸猫边学前端噢
		</p>
	</div>
	<img src="https://github-imglib-1255459943.cos.ap-chengdu.myqcloud.com/2code2.jpg" width="200" height="200" style="display:block;margin: 0 auto;" />
	<p style="text-align: center;margin-top: 10px;margin-bottom: 20px;">码生艰难，写文不易，给我家猪囤点猫粮了喵~</p>
	<div class="author-right">
  		<p>作者：被删</p>
  		<p>出处：<a href="https://godbasin.github.io">https://godbasin.github.io</a></p>
  		<p>本文版权归作者所有，欢迎转载，但未经作者同意必须保留此段声明，且在文章页面明显位置给出原文连接，否则保留追究法律责任的权利。</p>
	</div>
		<footer class="article-footer clearfix">

  <div class="article-tags">
  
  <span></span> <a href="/tags/笔记/">笔记</a>
  </div>


<div class="article-categories">
  <span></span>
  <a class="article-category-link" href="/categories/react沙拉/">react沙拉</a>
</div>



<div class="article-share" id="share">

  
<!-- JiaThis Button BEGIN -->
<div class="jiathis_style_24x24">
	<a class="jiathis_button_qzone"></a>
	<a class="jiathis_button_tsina"></a>
	<a class="jiathis_button_tqq"></a>
	<a class="jiathis_button_weixin"></a>
	<a class="jiathis_button_renren"></a>
	<a href="http://www.jiathis.com/share?uid=2134021" class="jiathis jiathis_txt jtico jtico_jiathis" target="_blank"></a>
</div>
<script type="text/javascript">
var jiathis_config = {data_track_clickback:'true'};
</script>
<script type="text/javascript" src="http://v3.jiathis.com/code_mini/jia.js?uid=2134021" charset="utf-8"></script>
<!-- JiaThis Button END -->   


</div>
</footer>   	       
	</article>
	
<nav class="article-nav clearfix">
 
 <div class="prev" >
 <a href="/2016/08/27/react-notes-7-form-and-ref/" title="React使用笔记7--关于Refs和React表单">
  <strong>PREVIOUS:</strong><br/>
  <span>
  React使用笔记7--关于Refs和React表单</span>
</a>
</div>


<div class="next">
<a href="/2016/08/20/react-notes-5-fullfill-index/"  title="React使用笔记5--理解jsx以及制作index页面">
 <strong>NEXT:</strong><br/> 
 <span>React使用笔记5--理解jsx以及制作index页面
</span>
</a>
</div>

</nav>

	<!-- 如果不是首页且没使用 `comments: false` 关闭评论，则尝试加载评论 -->

    <!-- 配置中启用多说时，导入相应代码 -->
    


</div>  
      <div class="openaside"><a class="navbutton" href="#" title="显示侧边栏"></a></div>

  <div id="toc" class="toc-aside">
  <strong class="toc-title">文章目录</strong>
  <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#React-Flux架构简介"><span class="toc-number">1.</span> <span class="toc-text">React Flux架构简介</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#什么是Flux"><span class="toc-number">1.1.</span> <span class="toc-text">什么是Flux</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Flux基本概念"><span class="toc-number">1.2.</span> <span class="toc-text">Flux基本概念</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Flux数据流"><span class="toc-number">1.3.</span> <span class="toc-text">Flux数据流</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#参考"><span class="toc-number">1.4.</span> <span class="toc-text">参考</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#使用Flux"><span class="toc-number">2.</span> <span class="toc-text">使用Flux</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#目录组织"><span class="toc-number">2.1.</span> <span class="toc-text">目录组织</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#添加HeaderStore"><span class="toc-number">2.2.</span> <span class="toc-text">添加HeaderStore</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#通过Controller-View传递数据"><span class="toc-number">2.3.</span> <span class="toc-text">通过Controller-View传递数据</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#添加Actions"><span class="toc-number">2.4.</span> <span class="toc-text">添加Actions</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#注册Store到Dispatcher"><span class="toc-number">2.5.</span> <span class="toc-text">注册Store到Dispatcher</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#结束语"><span class="toc-number">3.</span> <span class="toc-text">结束语</span></a></li></ol>
  </div>

<div id="asidepart">
<div class="closeaside"><a class="closebutton" href="#" title="隐藏侧边栏"></a></div>
<aside class="clearfix">

  	
	<div class="archiveslist">
		<p class="asidetitle">最近文章</p>
			<ul class="archive-list">
			
					
				<li class="archive-list-item">
					<a class="archive-list-link" href="/2019/11/15/wxapp-latest-20191115/" title="小程序开发月刊第11期（20191115）">小程序开发月刊第11期（201911...</a>
				</li>
				
			
					
				<li class="archive-list-item">
					<a class="archive-list-link" href="/2019/11/10/change-log/" title="前端 CHANGELOG 生成指南">前端 CHANGELOG 生成指南...</a>
				</li>
				
			
					
				<li class="archive-list-item">
					<a class="archive-list-link" href="/2019/11/09/wxapp-global-data-behavior/" title="小程序的奇技淫巧 -- globalDataBehavior管理全局状态">小程序的奇技淫巧 -- global...</a>
				</li>
				
			
					
				<li class="archive-list-item">
					<a class="archive-list-link" href="/2019/10/15/wxapp-latest-20191015/" title="小程序开发月刊第十期（20191015）">小程序开发月刊第十期（2019101...</a>
				</li>
				
			
					
				<li class="archive-list-item">
					<a class="archive-list-link" href="/2019/10/13/about-front-end-3-growth/" title="前端这几年--3.关于成长和焦虑">前端这几年--3.关于成长和焦虑...</a>
				</li>
				
			
					
				<li class="archive-list-item">
					<a class="archive-list-link" href="/2019/09/16/wxapp-latest-20190916/" title="小程序开发月刊第九期（20190916）">小程序开发月刊第九期（2019091...</a>
				</li>
				
			
					
				<li class="archive-list-item">
					<a class="archive-list-link" href="/2019/08/15/wxapp-latest-20190815/" title="小程序开发月刊第八期（20190815）">小程序开发月刊第八期（2019081...</a>
				</li>
				
			
					
				<li class="archive-list-item">
					<a class="archive-list-link" href="/2019/07/27/front-end-playground/" title="被删的前端游乐场建成！">被删的前端游乐场建成！</a>
				</li>
				
			
					
				<li class="archive-list-item">
					<a class="archive-list-link" href="/2019/07/21/vue-for-everyone-3/" title="9102全员学Vue--3.把页面拼成个Web应用">9102全员学Vue--3.把页面拼...</a>
				</li>
				
			
					
				<li class="archive-list-item">
					<a class="archive-list-link" href="/2019/07/15/wxapp-latest-20190715/" title="小程序开发月刊第七期（20190715）">小程序开发月刊第七期（2019071...</a>
				</li>
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
				
			
			</ul>
	</div>


  
  <div class="archiveslist">
    <p class="asidetitle"><a href="/archives">归档</a></p>
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/11/">十一月 2019</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/10/">十月 2019</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/09/">九月 2019</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/08/">八月 2019</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/07/">七月 2019</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/06/">六月 2019</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/05/">五月 2019</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/04/">四月 2019</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/03/">三月 2019</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/02/">二月 2019</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/01/">一月 2019</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/12/">十二月 2018</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/11/">十一月 2018</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/10/">十月 2018</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/09/">九月 2018</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/08/">八月 2018</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/07/">七月 2018</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/06/">六月 2018</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/05/">五月 2018</a><span class="archive-list-count">5</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/04/">四月 2018</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/03/">三月 2018</a><span class="archive-list-count">7</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/02/">二月 2018</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/01/">一月 2018</a><span class="archive-list-count">9</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/12/">十二月 2017</a><span class="archive-list-count">5</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/11/">十一月 2017</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/10/">十月 2017</a><span class="archive-list-count">5</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/09/">九月 2017</a><span class="archive-list-count">6</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/08/">八月 2017</a><span class="archive-list-count">11</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/07/">七月 2017</a><span class="archive-list-count">9</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/06/">六月 2017</a><span class="archive-list-count">10</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/05/">五月 2017</a><span class="archive-list-count">15</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/04/">四月 2017</a><span class="archive-list-count">7</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/03/">三月 2017</a><span class="archive-list-count">10</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/02/">二月 2017</a><span class="archive-list-count">41</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/01/">一月 2017</a><span class="archive-list-count">6</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/12/">十二月 2016</a><span class="archive-list-count">7</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/11/">十一月 2016</a><span class="archive-list-count">9</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/10/">十月 2016</a><span class="archive-list-count">5</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/09/">九月 2016</a><span class="archive-list-count">7</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/08/">八月 2016</a><span class="archive-list-count">9</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/07/">七月 2016</a><span class="archive-list-count">14</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/06/">六月 2016</a><span class="archive-list-count">9</span></li></ul>
  </div>


  
<div class="archiveslist">
	<p class="asidetitle"><a href="/categories">分类</a></p>
		<ul class="archive-list">
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/CSS炒饭/" title="CSS炒饭">CSS炒饭<sup>3</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/D3小馒头/" title="D3小馒头">D3小馒头<sup>8</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/angular2火锅/" title="angular2火锅">angular2火锅<sup>25</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/angular混搭/" title="angular混搭">angular混搭<sup>33</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/box2djs方糖/" title="box2djs方糖">box2djs方糖<sup>34</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/cyclejs哈根达斯/" title="cyclejs哈根达斯">cyclejs哈根达斯<sup>8</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/jQuery杂烩/" title="jQuery杂烩">jQuery杂烩<sup>3</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/js什锦/" title="js什锦">js什锦<sup>26</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/react沙拉/" title="react沙拉">react沙拉<sup>16</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/three-js奶茶/" title="three.js奶茶">three.js奶茶<sup>5</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/vue八宝粥/" title="vue八宝粥">vue八宝粥<sup>29</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/webpack宾治/" title="webpack宾治">webpack宾治<sup>9</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/web乱炖/" title="web乱炖">web乱炖<sup>2</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/前端满汉全席/" title="前端满汉全席">前端满汉全席<sup>8</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/喵/" title="喵">喵<sup>2</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/小程序双皮奶/" title="小程序双皮奶">小程序双皮奶<sup>27</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/工作这杯茶/" title="工作这杯茶">工作这杯茶<sup>5</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/应用巧克力盒/" title="应用巧克力盒">应用巧克力盒<sup>2</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/思想棉花糖/" title="思想棉花糖">思想棉花糖<sup>8</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/柴米油盐工具集/" title="柴米油盐工具集">柴米油盐工具集<sup>1</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/自动化甜筒/" title="自动化甜筒">自动化甜筒<sup>1</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/categories/非前端钙片/" title="非前端钙片">非前端钙片<sup>7</sup></a>
			</li>
		
		</ul>
</div>


  
<div class="archiveslist">
	<p class="asidetitle">标签</p>
		<ul class="archive-list">
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/tags/分享/" title="分享">分享<sup>44</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/tags/原创部件/" title="原创部件">原创部件<sup>1</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/tags/心态/" title="心态">心态<sup>5</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/tags/教程/" title="教程">教程<sup>73</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/tags/晒猫/" title="晒猫">晒猫<sup>2</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/tags/笔记/" title="笔记">笔记<sup>121</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/tags/算法/" title="算法">算法<sup>9</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/tags/自制插件/" title="自制插件">自制插件<sup>2</sup></a>
			</li>
		
			<li class="archive-list-item">
				<a class="archive-list-link" href="/tags/逻辑实现/" title="逻辑实现">逻辑实现<sup>5</sup></a>
			</li>
		
		</ul>
</div>


    <div class="archiveslist">
    <p class="asidetitle"><a href="/archives">about</a></p>
      <ul class="archive-list">
      	<li class="archive-list-item">
      		<a>wangbeishan@163.com</a>
      		<a href="https://github.com/godbasin">github.com/godbasin</a>
      	</li>
      </ul>
  </div>

  <div class="rsspart">
	<a href="/atom.xml" target="_blank" title="rss">RSS 订阅</a>
</div>

</aside>
</div>
    </div>
    <footer><div id="footer" >
	
	<section class="info">
		<p> 即使梦想再小，却很伟大 ^_^ </p>
	</section>
	 
		<p class="copyright">Powered by <a href="http://hexo.io" target="_blank" title="hexo">hexo</a> and Theme by <a href="https://github.com/A-limon/pacman" target="_blank" title="Pacman">Pacman</a> © 2019 
		
		<a href="https://godbasin.github.io" target="_blank" title="被删">被删</a>
		
		</p>
</div>
</footer>
    <script src="/js/jquery-2.1.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){ 
  $('.navbar').click(function(){
    $('header nav').toggleClass('shownav');
  });
  var myWidth = 0;
  function getSize(){
    if( typeof( window.innerWidth ) == 'number' ) {
      myWidth = window.innerWidth;
    } else if( document.documentElement && document.documentElement.clientWidth) {
      myWidth = document.documentElement.clientWidth;
    };
  };
  var m = $('#main'),
      a = $('#asidepart'),
      c = $('.closeaside'),
      o = $('.openaside');
  $(window).resize(function(){
    getSize(); 
    if (myWidth >= 1024) {
      $('header nav').removeClass('shownav');
    }else
    {
      m.removeClass('moveMain');
      a.css('display', 'block').removeClass('fadeOut');
      o.css('display', 'none');
      
      $('#toc.toc-aside').css('display', 'none');
        
    }
  });
  c.click(function(){
    a.addClass('fadeOut').css('display', 'none');
    o.css('display', 'block').addClass('fadeIn');
    m.addClass('moveMain');
  });
  o.click(function(){
    o.css('display', 'none').removeClass('beforeFadeIn');
    a.css('display', 'block').removeClass('fadeOut').addClass('fadeIn');      
    m.removeClass('moveMain');
  });
  $(window).scroll(function(){
    o.css("top",Math.max(80,260-$(this).scrollTop()));
  });
});
</script>

<script type="text/javascript">
$(document).ready(function(){ 
  var ai = $('.article-content>iframe'),
      ae = $('.article-content>embed'),
      t  = $('#toc'),
      h  = $('article h2')
      ah = $('article h2'),
      ta = $('#toc.toc-aside'),
      o  = $('.openaside'),
      c  = $('.closeaside');
  if(ai.length>0){
    ai.wrap('<div class="video-container" />');
  };
  if(ae.length>0){
   ae.wrap('<div class="video-container" />');
  };
  if(ah.length==0){
    t.css('display','none');
  }else{
    c.click(function(){
      ta.css('display', 'block').addClass('fadeIn');
    });
    o.click(function(){
      ta.css('display', 'none');
    });
    $(window).scroll(function(){
      ta.css("top",Math.max(140,320-$(this).scrollTop()));
    });
  };
});
</script>







  </body>
</html>
